package com.easyj.base.util;

import java.text.SimpleDateFormat;  
import java.util.Date; 
public class BillCodeGen {

	private static SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
	  /** 
	   * 锁对象
	   */  
	  private static Object lockObj = "lockerOrder";  
	  /** 
	   * 单号生成计数器 
	   */  
	  private static long orderNumCount = 0L;  
	  /** 
	   * 每秒生成单号数量最大值 
	   */  
	  private  static int maxPerMSECSize=10000;  
	   
	  public static String genCode(String prex) {  
           // 最终生成的单号  
          String finOrderNum;  
          synchronized (lockObj) {        	  
        	  finOrderNum=prex;      	  
              // 取系统当前时间作为订单号变量前半部分
        	  finOrderNum+=format.format(new Date());
              if (orderNumCount > maxPerMSECSize) {  
                  orderNumCount = 0L;  
              }  
              //组装订单号  
              String countStr=(maxPerMSECSize +orderNumCount)+"";  
              finOrderNum+=countStr.substring(1);  
              orderNumCount++;
          }  
          
          return finOrderNum;
	     
	  }  


}
